import state from './examlist'

export default  {
    namespaced: true,
    state:()=>state,
    getters:{
        //获取当前答题总数
        getListCount: state => state.list.arrList.length,
        //获取题目
        getCount: state => state.list.arrList,
        //返回下标对应的题目
        getListCountName: state => state.list.arrList[state.list.index],

        /**返回题目ID对应的下标 */
        getCentreIndex: state => id => state.list.arrList.findIndex(item => item.id === id),

        //通过答案获取下标
        getAnswerById:state=>(Bid,Xid)=>{
            let index=state.list.arrList.findIndex(item=>item.id===Bid)
            return state.list.arrList[index].options.findIndex(item=>item.id===Xid)
        },
        //获取正确题目数
        getCentreCount(state){
            return state.list.arrList.filter(item => item.correct === item.choice).length
        },
        //未答题数
        getNotCentreCount(state){
            return state.list.arrList.filter(item => item.choice === -1).length
        },
        //答题时间
        getTimestate :state => state.list.time,
     

    },
    mutations:{
        //修改当前题目下标
        setListIndex(state, params){
            state.list.index=params.index
        },
        //存入用户所选结果 (arrListId  answerId)
        setListAnswer(state, params){
            let index=state.list.arrList.findIndex(item => item.id ===params.arrListId)
        //修改答题结果并存入
            state.list.arrList[index].choice =params.answerId
        },

        //还原题目状态
        setNameAnswer(state){
            //还原答题顺序
            state.list.index = 0

            //还原题目答案状态
            state.list.arrList.forEach(item => {
                item.choice = -1
            });
        },
        //存入答题时间
        setTime(state,params){
            state.list=params
        },
    },
}